<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="患者id" prop="patientId">
        <el-input
          v-model="queryParams.patientId"
          placeholder="请输入患者id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="diagnosisList">
      <el-table-column label="序号" align="center">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="日期" align="center" prop="diagnoseTime" width="180">
        <template #default="scope">
          {{scope.row.quantity}}
        </template>
      </el-table-column>
      <el-table-column label="总金额" align="center" prop="totalAmount" >
        <template #default="scope">
          {{scope.row.totalAmount}}
        </template>
      </el-table-column>
      <el-table-column label="患者数量" align="center" prop="quantity">
        <template #default="scope">
          {{scope.row.quantity}}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="findDetail(scope.row)">查看</el-button>
          <el-button link type="primary" icon="Delete" @click="findAppraise(scope.row)">评价</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>

  <el-dialog v-model="dialogTableVisible" title="评价" width="800">
    <el-table :data="evaluateForm">
      <el-table-column label="序号" align="center">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column property="patientName" label="姓名" width="200" />
      <el-table-column property="message" label="病情描述" width="200" />
      <el-table-column property="evaluate" label="评价" width="200" />
      <el-table-column property="starLevel" label="星评" width="200" />
    </el-table>
    <button @click="dialogTableVisible=false">关闭</button>
  </el-dialog>
</template>

<script setup name="Diagnosis">
import { listDiagnosis, getDiagnosis, delDiagnosis, addDiagnosis, updateDiagnosis } from "@/api/doctor/diagnosis";
import {parseTime} from "../../../utils/ruoyi.js";
import {useRoute, useRouter} from "vue-router";

const dialogTableVisible = ref(false)
const { proxy } = getCurrentInstance();

const diagnosisList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const route = useRoute();
const router = useRouter();
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    diagnoseId:null,
    diagnoseTime: null,
    totalAmount: null,
    quantity:null
  },
  rules: {
  },
  evaluateForm: []
});

const { queryParams, form, rules, evaluateForm} = toRefs(data);

/** 查询诊断管理列表 */
function getList() {
  loading.value = true;
  listDiagnosis(queryParams.value).then(response => {
    diagnosisList.value = response.data;
    total.value = response.data;
    loading.value = false;
  });
}
//查看详情
function findDetail(data){
  router.push({path:"/detail/index",query:{date:data.diagnoseTime}})
}
//查看评价
function findAppraise(){
  dialogTableVisible.value=true
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
// 表单重置
function reset() {
  form.value = {
    diagnoseId: null,
    patientId: null,
    doctorId: null,
    diagnoseDiseaseDescription: null,
    diagnoseDiagnosis: null,
    diagnoseTime: null,
    diagnosePrice: null
  };
  proxy.resetForm("diagnosisRef");
}


getList();
</script>
